package com.liu.demo.config;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.validation.constraints.Email;
import java.util.Locale;
/**
 *功能描述 配置视图解析器
 * @author QS.L
 * @date 2020/5/16
 */
@Configuration

public class MyMvcConfig implements WebMvcConfigurer {


    /**
     *功能描述 配置控制器跳转界面
     * @author QS.L
     * @date 2020/5/16
     */
    @Email
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/index").setViewName("index");
    }

    @Bean("viewResolver")
    public ViewResolver ViewResolver(){
        return new MyViewResolver();
    }
    @Bean("localeResolver")//此处必须为localeResolver，方法名字可以改变但是必须指定名字为localeResolver
    public LocaleResolver localeResolver(){
        return new MyLocalResolver();
    }

    /* 自定义视图解析器 */
    public static class MyViewResolver implements ViewResolver{
        @Override
        public View resolveViewName(String s, Locale locale) throws Exception {
            return null;
        }
    }
}
